<!DOCTYPE html>
<html lang="en">
    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实时监控</title>


<link href="../../assets/plugins/bootstrapv3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="../../assets/plugins/bootstrap-treeview/css/bootstrap-treeview.css" rel="stylesheet">


<script src="../../assets/plugins/jquery/jquery-1.11.3.min.js" type="text/javascript"></script>


  <!-- 以下是事件触发函数接口 -->  
<script language="javascript" for="preview" event="MsgNotify(iMsg,iError,szDetail,lWnd,szIndexCode)">
    szMsg = "msg:" + iMsg + ",error:" + iError + ",detail:" + szDetail + "，IndexCode：" + szIndexCode;
    $("#Result").val(szMsg);
    
    
    //return;
    //alert(szMsg);
    //0x02000007事件，控件加载完成时抛出的消息，此时平台根据需要调用以下接口对控件进行初始化
    //（控件内部默认也对应设置了固定参数，但生产现场要使用上次用户设置保存的参数，需要平台把上一次保存的数据设置进去）
    if (iMsg == 0x02000007)
    {
      var _right = "10034,10033,10032,10020,10027,10014,10001,10028,10002,10015,10005,10010,10024,10006,10011,10003,10021,10012,10022,10004,10013,10009,10029";
      preview.SetRightCode(_right);
      var _toolbar = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        + "<ToolBar><Item type=\"0\" /><Item type=\"24\" /><Item type=\"5\" />"
        + "<Item type=\"6\" /><Item type=\"7\" /><Item type=\"8\" />"
        + "<Item type=\"9\" /><Item type=\"10\" /><Item type=\"12\" />"
        + "<Item type=\"17\" /><Item type=\"20\" /><Item type=\"21\" />"
        + "<Item type=\"22\" /><Item type=\"53\" /><Item type=\"54\" /></ToolBar>";
      preview.SetToolBar(_toolbar);//工具栏按钮
      preview.SetToolBarAlwaysShow(0);
      preview.SetInstPlayCfg(30);//即使回放播放时间
      var _snap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        + "<SnapShot><PicType>jpeg</PicType><Quality>80</Quality><SnapMulti>1</SnapMulti>"
        + "<SnapTimes>3</SnapTimes><TimeSpan>1</TimeSpan><SaveFolder>C:\\Users\\lichanghua\\Documents\\CSC\\capture\\</SaveFolder><KeyWords></KeyWords></SnapShot>";
      preview.SetSnapParam(_snap);//抓图参数设置
      var _record = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
        + "<VideoRecord><PackType>0</PackType><MaxRecTime>0</MaxRecTime>"
        + "<PackTime>100</PackTime><PackSize>100</PackSize><SaveFolder>C:\\Users\\lichanghua\\Documents\\CSC\\record\\</SaveFolder><KeyWords></KeyWords></VideoRecord>";
      preview.SetRecordParam(_record);//录像参数设置
    }
</script>
    <SCRIPT type=text/javascript>
    function LoginPlat()
    {
      //Demo默认使用密码登录方式
    //  var IP = document.frmApp.IP.value;
    //  var port = document.frmApp.port.value;
    //  var UserName = document.frmApp.UserName.value;
    //  var Password = document.frmApp.Password.value;
      
      var IP = "10.1.1.4";
      var port = "9980";
      var UserName = "hbhdty";
      var Password = "jiuan@110";
  
      
      var v1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><LoginInfo><LoginType>2</LoginType><SynLogin>1</SynLogin><IP>"+IP+"</IP><Port>"+port
      +"</Port><UserName>"+UserName+"</UserName><Password>"+Password+"</Password></LoginInfo>";
      //alert(v1);
      var v = preview.LoginPlat(v1);
      if(v != 0)
      alert("登录失败，请查看日志preview.log");
    }

    //新的预览接口，需先登录平台，登录需要耗点时间，稍等（控件自身取Token）
    function StartPreview(id)
    {
      //var Code = document.frmApp.CameraIndexCode.value;
      var Code = id;
      var _param = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Preview><CamIndexCode>"+Code+"</CamIndexCode></Preview>";
      
      preview.StartPreview( _param);
    }
    
    //老预览接口：控件仍然抛事件给平台，由平台传入Token
    //2015.10.8之前的版本，老接口预览，没登录平台token会为空，如果服务要验证token，预览会失败，只能通过登录平台方式预览
    function StartPreviewEx()
    {
      var IP = document.frmApp.VAGIP.value;
      var port = document.frmApp.VAGPort.value;
      var Code = document.frmApp.CameraIndexCode.value;
      //根据平台不同的取流配置方式，控件开始预览接口StartPreviewEx(BSTR szXml)包含以下三种情况
            //取流方式一：过Vag直连取流(非级联)
      var stream_vag_param = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Preview>"
               + "<StreamSvr>"
             + "<Svr type=\"3\" ip=\""+IP+"\" port=\""+port+"\"/>"              //过Vag直连取流：提供监控点所在的Vag服务IP和端口
             + "</StreamSvr>"                                   
             + "<CamIndexCode>"+Code+"</CamIndexCode>"                          //监控点编号：对应平台监控点信息"c_index_code"字段
             + "<CamName>小区Camera01</CamName>"                          //监控点名称：对应平台监控点信息"c_name"字段
             + "<DevIndexCode>10000000001130000003</DevIndexCode>"                          //监控点所在设备编号：对应平台监控点信息"c_device_index_code"字段
             + "<LinkType>1</LinkType>"                                   //取流连接协议：1~TCP(默认), 2~UDP，对应平台监控点信息"i_stream_link_type"字段
             + "<StreamType>0</StreamType>"                                 //码流类型：0~主码流, 1~子码流,对应平台监控点信息"i_stream_type"字段  
             + "<ChannelNo>1</ChannelNo>"                                 //监控点所在设备通道号：对应监控点信息“i_channel_no”字段
             + "<NetZone cnid=\"1\" pnid=\"1\"/>"                       //客户端和设备所在网域Id，内网~1(默认)，外网~2，pnid对应设备信息"i_netDemain_id"字段
             + "<UserLevel>50</UserLevel>"                            //平台用户等级，50~系统管理员
             + "<DevType>0</DevType>"                                 //监控点所在设备设备厂商类型：0~海康，1~大华，其他参考平台设备,对应平台设备信息"i_device_detail_type"字段
             + "<ProSeries>1</ProSeries>"                               //监控点所在设备对应产品系列,对应平台设备信息"i_manufacturer"字段
             + "<TreatyType>SDK</TreatyType>"                         //监控点所在设备产品接入协议：SDK~海康SDK设备, EHOME~EHOME设备, GB28181~国标设备等,对应平台设备信息"c_treaty_type"字段
             + "<UserName>admin</UserName>"                         //监控点所在设备用户名,对应平台设备信息"c_user_name"字段 
             + "<PassWord>XdMOANI=</PassWord>"                        //监控点所在设备密码,对应平台设备信息"c_user_pwd"字段
             + "<FishEyeInfo><InstallType></InstallType><VideoDevType>16</VideoDevType></FishEyeInfo>" //[可选]对于鱼眼监控点使用：安装方式和设备类型
             + "</Preview>";

      //取流方式二：过流媒体取流(非级联)
      var stream_vtm_param = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Preview>"
               + "<StreamSvr>"                                  //过流媒体取流需同时提供Vag服务和流媒体服务信息，其中流媒体服务可以是Vtm或Vtdu，取决于平台配置的服务
             + "<Svr type=\"3\" ip=\"10.33.30.205\" port=\"7302\"/>"              //Vag服务
             + "<Svr type=\"4\" ip=\"10.33.30.205\" port=\"557\"/>"             //Vtm或Vtdu服务 
             + "</StreamSvr>"     
             + "<CamIndexCode>10000000001310000019</CamIndexCode>"              //监控点编号：对应平台监控点信息"c_index_code"字段
             + "<CamName>小区Camera01</CamName>"                          //监控点名称：对应平台监控点信息"c_name"字段
             + "<DevIndexCode>10000000001130000003</DevIndexCode>"                          //监控点所在设备编号：对应平台监控点信息"c_device_index_code"字段
             + "<LinkType>1</LinkType>"                                   //取流连接协议：1~TCP(默认), 2~UDP，对应平台监控点信息"i_stream_link_type"字段
             + "<StreamType>0</StreamType>"                                 //码流类型：0~主码流, 1~子码流,对应平台监控点信息"i_stream_type"字段  
             + "<ChannelNo>1</ChannelNo>"                                 //监控点所在设备通道号：对应监控点信息“i_channel_no”字段
             + "<NetZone cnid=\"1\" pnid=\"1\"/>"                       //客户端和设备所在网域Id，内网~1(默认)，外网~2，pnid对应设备信息"i_netDemain_id"字段
             + "<UserLevel>50</UserLevel>"                            //平台用户等级，50~系统管理员
             + "<DevType>0</DevType>"                                 //监控点所在设备设备厂商类型：0~海康，1~大华，其他参考平台设备,对应平台设备信息"i_device_detail_type"字段
             + "<ProSeries>1</ProSeries>"                               //监控点所在设备对应产品系列,对应平台设备信息"i_manufacturer"字段
             + "<TreatyType>SDK</TreatyType>"                         //监控点所在设备产品接入协议：SDK~海康SDK设备, EHOME~EHOME设备, GB28181~国标设备等,对应平台设备信息"c_treaty_type"字段
             + "<UserName>admin</UserName>"                         //监控点所在设备用户名,对应平台设备信息"c_user_name"字段 
             + "<PassWord>XdMOANI=</PassWord>"                        //监控点所在设备密码,对应平台设备信息"c_user_pwd"字段
             + "<FishEyeInfo><InstallType></InstallType><VideoDevType>16</VideoDevType></FishEyeInfo>" //[可选]对于鱼眼监控点使用：安装方式和设备类型
             + "</Preview>"; 
             
      //取流方式三：级联过NCG取流
      var stream_ncg_param = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Preview>"
               + "<StreamSvr>"                                  //级联取流提供NCG服务的IP和端口
             + "<Svr type=\"8\" ip=\"10.33.30.205\" port=\"7099\"/>"              //NCG服务
             + "</StreamSvr>"  
             + "<CascCode>999999990020000000022</CascCode>"                 //级联监控点编码标志，通过该字段区分是否为级联监控点及是否级联过NCG取流，对应平台监控点信息"c_cascade_privilege"字段
             + "<DecodeTag>hikvision</DecodeTag>"                       //级联监控点编码标志：hikvision~海康设备，dahua~大华设备，db33~国标设备，通过该字段区别进行解码播放，对应平台监控点信息"c_decode_tag"字段
             + "<CamIndexCode>10000000001310000019</CamIndexCode>"              //监控点编号
             + "<CamName>Camera01</CamName>"                          //监控点名称
             + "<ChannelNo>1</ChannelNo>"                           //监控点所在设备通道号
             + "<NetZone cnid=\"1\" pnid=\"\"/>"                                //客户端和设备所在网域Id，内网~1，外网~2，注：级联时无设备信息
             + "<LinkType>1</LinkType>"                           //[预留，暂不使用]取流连接协议：1~TCP(默认), 2~UDP
             + "<StreamType>0</StreamType>"                         //[预留，暂不使用]码流类型：0~主码流, 1~子码流
             + "</Preview>"; 

      //alert(stream_vag_param);
      preview.StartPreviewEx(stream_vag_param);
    }
    
    function StopPreview()
    {
      var idx = preview.GetSelWnd();
      preview.StopPreview(idx);
    }
    
    function StopAll()
    {
      var v = preview.StopPreview(-1);
    }
    
    //以下接口可能不常用，请按需求使用
    function PtzControl()
    {
      var Code = document.frmApp.CameraIndexCode.value;
        var vFunid = document.frmApp.FunId.value;
        var CmdId = document.frmApp.CmdId.value;
        var vSpeed = document.frmApp.Speed.value;
        var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>" + vFunid + "</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify><Param>1</Param>"
                  + "<ControInfo><CmdId>"+CmdId+"</CmdId><Action></Action><Speed>"+vSpeed+"</Speed></ControInfo>"
                  + "<PresetInfo><Info No=\"1\" Name=\"2\" Type=\"1\" /><Info No=\"2\" Name=\"3\" Type=\"2\" /></PresetInfo>"
                  + "<CruiseInfo><Info No=\"1\" Dwell=\"1\" Speed=\"1\" /><Info No=\"2\" Dwell=\"2\" Speed=\"2\" /></CruiseInfo></PtzControl>";
        //alert(_param);
        var v = preview.PtzControl(_param);
        alert(v);
    }
    
    function AddSecuriteZone()//添加信任站点
    {
      var IP = document.frmApp.IP.value;
      var v = preview.AddSecuriteZone(IP);
    }
    function EnterFishEye()//进入鱼眼模式
    {
      preview.EnterFishEye();
    }
    function ExitFishEye()//退出鱼眼模式
    {
      preview.ExitFishEye();  
    }
    function SetLayoutType()//设置窗口布局
    {
      var v = document.frmApp.Layout.value;
      preview.SetLayoutType(v);
    }
    function SetInstPlayCfg()//设置即时回放时间
    {
      var v1 = document.frmApp.data.value;
      var v = preview.SetInstPlayCfg(v1);
    }
    function GetVersion()//获取版本号
    {
      var v = preview.GetVersion();
      alert(v);
    }
    function SetPerCfgInfo()//设置性能计划，如预览大于9路自动切换为子码流，双击放大单窗口显示时自动切换为主码流
    {
      var v1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Per><ChgWndNum>9</ChgWndNum><AutoChg>1</AutoChg><DecodePer>5</DecodePer><PlayPer>0</PlayPer></Per>";
      var v = preview.SetPerCfgInfo(v1);
    }
    function EnableMenu()//设置鼠标右键菜单栏是否启用
    {
      var v1 = document.frmApp.data.value;
      var v = preview.EnableMenu(v1);
    }
    function GetDirectoryPath()//弹出目录选择框，返回最终用户选择的路径
    {
      var v = preview.GetDirectoryPath();
    }
    function GetSystemDrive()//获取当前系统驱动盘符
    {
      var v = preview.GetSystemDrive();
      alert(v);
    }
    function GetUserDocument()//获取用户文档目录
    {
      var v = preview.GetUserDocument();
      alert(v);
    }
    function GetSelWndIsPlay()//获取当前选中窗口是否在播放状态
    {
      var v = preview.GetSelWndIsPlay();
      alert(v);
    }
    
    function SetMainToolBarShow()//设置主工具栏的显示隐藏
    {
      var data = document.frmApp.data.value;
      preview.SetMainToolBarShow(data);
    }
    function SetToolBarVisible()//设置播放窗口的小工具栏的显示隐藏
    {
      var data = document.frmApp.data.value;
      preview.SetToolBarVisible(data);
    }
    function EnableSysCfgButton()//设置系统设置按钮的使能控制
    {
      var data = document.frmApp.data.value;
      preview.EnableSysCfgButton(data);
    }
    
    function ShowFullScreenButton()//设置切换全屏按钮的显示隐藏
    {
      var data = document.frmApp.data.value;
      preview.ShowFullScreenButton(data);
    }
    
    //云镜控制各接口
    function zoomin()//焦距缩小
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>12</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
                    
      var v = preview.PtzControl(_param);
      //alert(v);
    }
    function zoomout()//焦距放大
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>11</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function qianyi()//焦点前移
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>14</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function houyi()//焦点后移
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>13</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function zoomin2()//光圈缩小
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>16</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function zoomout2()//光圈放大
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>15</CmdId><Action></Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function lock()//锁定
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>1</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify><Param>60</Param></PtzControl>";//60秒
      var v = preview.PtzControl(_param);
      alert(v);
    }
    function unlock()//解锁
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>2</FunId> <CamIndexCode>"+Code+"</CamIndexCode><MsgNotify>0</MsgNotify></PtzControl>";//60秒
      var v = preview.PtzControl(_param);
      alert(v);
    }
    function DZoom()//设置当前窗口3D放大状态
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vDZoom = document.frmApp.data.value;
      if (vDZoom != 0)
      {
        vDZoom = 1;
        document.frmApp.data.value = 0;
      }
      else
        document.frmApp.data.value = 1;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>3</FunId><CamIndexCode>"+Code+"</CamIndexCode><Param>"+vDZoom+"</Param></PtzControl>";
      var v = preview.PtzControl(_param);
      alert(v);
    }
    function dengguang()
    {
      var vOpen = document.frmApp.data.value;//控制打开还是关闭灯光
      if (vOpen != 0)
      {
        vOpen = 1;
        document.frmApp.data.value = 0;
      }
      else
        document.frmApp.data.value = 1;
      var Code = document.frmApp.CameraIndexCode.value;
      var vFunid = document.frmApp.FunId.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>2</CmdId><Action>"+vOpen+"</Action><Param></Param><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
      alert(v);
    }
    function yushua()
    {
      var vOpen = document.frmApp.data.value;//控制打开还是关闭雨刷
      if (vOpen != 0)
      {
        vOpen = 1;
        document.frmApp.data.value = 0;
      }
      else
        document.frmApp.data.value = 1;
      
      var Code = document.frmApp.CameraIndexCode.value;
      var vFunid = document.frmApp.FunId.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>3</CmdId><Action>"+vOpen+"</Action><Param></Param><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
      alert(v);
    }
    function scan()
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vScan = document.frmApp.data.value;
      if (vScan != 0)
      {
        vScan = 1;
        document.frmApp.data.value = 0;
      }
      else
        document.frmApp.data.value = 1;
        
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify><Param>0</Param>"
                  + "<ControInfo><CmdId>29</CmdId><Action>"+ vScan +"</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    //八方向
  /*   function top()//向上
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>21</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    } */
    function righttop()//右上
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>26</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function right()//向右
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>24</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function rightbottom()//右下
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>28</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function bottom()//向下
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>22</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function leftbottom()//左下
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>27</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function left()//向左
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>23</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    function lefttop()//左上
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vSpeed = document.frmApp.Speed.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>4</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Wait>0</Wait><MsgNotify>0</MsgNotify>"
                  + "<ControInfo><CmdId>25</CmdId><Action>0</Action><Speed>" + vSpeed + "</Speed></ControInfo></PtzControl>";
      var v = preview.PtzControl(_param);
    }
    
    //设置预置点
    function SetPresetInfo()
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>7</FunId> <CamIndexCode>"+Code+"</CamIndexCode><MsgNotify>0</MsgNotify>"
                  + "<PresetInfo><Info No=\"1\" Name=\"1\" Type=\"1\" /></PresetInfo></PtzControl>";
      var v = preview.PtzControl(_param);
      alert(v);
    }
    
    //获取预置点
    function GetPresetInfo()
    {
      var Code = document.frmApp.CameraIndexCode.value;
      var vType = document.frmApp.data.value;//预置点类型：1:预置点 2:巡航
      var _param = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  + "<PtzControl><FunId>5</FunId> <CamIndexCode>"+Code+"</CamIndexCode><Param>"+vType+"</Param></PtzControl>";
      var v = preview.PtzControl(_param);
      alert(v);
    }
    
    //642新增接口
    function EnterEagleEye()
    {
      var vCount = document.frmApp.data.value;//大鹰眼设备节点下监控点个数
      var v = preview.EnterEagleEye(v);
    }
    function ExitEagleEye()
    {
      var v = preview.ExitEagleEye();
    }
    function GetPtzTraceMode()
    {
      var v = preview.GetPtzTraceMode();
      alert(v);
    }
    function SetPtzTraceMode()
    {
      var vState = document.frmApp.data.value;//0或1
      var v = preview.SetPtzTraceMode(vState);
    }
    function SetBrowserType()
    {
      var vType = document.frmApp.data.value;//0或1
      var v = preview.SetBrowserType(vType);
    }
    function SwitchWindow()
    {
      var vIndex1 = document.frmApp.Speed.value;
      var vIndex2 = document.frmApp.data.value;
      var v = preview.SwitchWindow(vIndex1,vIndex2);
      alert(v);
    }
    function SetPlayWndStateText()
    {
      var vData = document.frmApp.Result.value;//0或1
      var vIndex = document.frmApp.data.value;
      var v = preview.SetPlayWndStateText(vIndex,vData);
    }
    
    
    
    
    </SCRIPT>


<script language="javascript" for="preview" event="MsgNotify(lMsgId,lErrorCode,szDetail,lWndId,szIndexCode)">




if(lMsgId == 0x02000018){
	

	
/* 	 var WsShell = null;
     try {
      WsShell = new ActiveXObject('WScript.Shell');
     }catch(e){
      WsShell = null;
      console.log("not WScript.Shell",e);
     }
     if(WsShell){
      WsShell.SendKeys('{F11}');
      console.log("WScript.Shell");
     }else{
       console.log("not WScript.Shell");
     } */
     
	
	var ttp = window;
	  $('body').addClass('fullscreen');
	do{
        ttp = ttp.parent;
        $(ttp.document.body).addClass('fullscreen');
    }while(ttp!=top);
	
  $(ttp.document.body).addClass('fullscreen');
  $('.main-wrap').css('margin-left','0');//全屏模式将包裹控件的main-wrap的margin-left置为0，保证yuyanTab的样式。 */
 

  $('#preview').css('height','1080');
}


/* if ($('#preview_ocx').hikui() != null) $('#preview_ocx').hikui().trigger("MsgNotify",lMsgId,lErrorCode,szDetail,lWndId,szIndexCode); */
</script>

</head>
<body>



<div class="container-fluid">
  
   <input type="text" name="Result" style="width:440px"  id="Result" value="" class="hide">
  
 
  <div class="row">
    <div class="col-sm-3" >
      <div id="tree"></div>   
    </div>
     <div class="col-sm-9">
      <div class="main-wrap">
          <div class="monitor-container" style="width: 100%; height: 100%; padding-bottom: 0px;">
	
		        <object name="preview" width="100%" height="800" id="preview" classid="clsid:BE020CC9-521F-4641-85E1-3B631B7ADDD9" codebase="/download/HIKOCX.CAB#version=6,3,5,0" ">
		        <param name="Ip" value="10.1.1.4"/>
		        <param name="UserName" value="hbhdty"/>
		        <param name="privilegeCode" value="0401,0402,"/>
		        <param name="Skin" value="lightblue"/>
		        </object>
		        </div>
		     </div>
     </div> 
    </div>
   
  </div>
</div>

  <SCRIPT type=text/javascript>

    function queryOrg(nodes, tgc){
      
      
      
    //创建XMLHttpRequest对象
    var xhr = new XMLHttpRequest();
    //打开连接
    xhr.open("post","http://10.1.1.4:9980/cms/services/ICuService?wsdl",true);
    //设置数据类型
    xhr.setRequestHeader("content-type","text/xml;charset=utf-8");
    //设置回调函数
    xhr.onreadystatechange=function(){
      
      //判断是否发送成功和判断服务端是否响应成功
      if(4 == xhr.readyState && 200 == xhr.status){
        var response = xhr.responseXML.documentElement;
    //    console.log(response);
        
        var node_ = response.getElementsByTagName('ns:return'); //example 
     //   console.log(node_);
        
        var node = node_[0]; //example 
    //    console.log(node);
        
      
        var va = node.textContent;
     //   console.log(va);
        
        var parser=new DOMParser();
        xmlDoc=parser.parseFromString(va,"text/xml");
    //    console.log(xmlDoc);
        
        
        //var response1 = xhr.responseXML.documentElement;
        //console.log(response1);
        
        var node_1 = xmlDoc.getElementsByTagName('row'); //example 
     //   console.log(node_1);
        
        
        for(var i = 0; i < node_1.length; i++){
      //    console.log(node_1[i]);
          
          var c_device_ip=node_1[i].getAttribute("c_device_ip"); 
          var c_index_code=node_1[i].getAttribute("c_index_code"); 
          
        //  alert(c_index_code);

          var c_name=node_1[i].getAttribute("c_name"); 
          
          var searchNodes = $("#tree").treeview('search',[c_name,{
            ignoreCase:true,
            exactMatch:true,
            revelResults:false
          }]);

          
    //      console.log(searchNodes);
          
          if(searchNodes.length == 0){

             $("#tree")
                        .treeview("addNode",
                        [
                          nodes.nodeId,
                            { node: { text:c_name, icon:"glyphicon glyphicon-facetime-video", i_id: 500, "c_device_ip":c_device_ip, "c_index_code":c_index_code }, silent: true }
                        ]);
          }
          //alert(c_name);   
        }
        
      }
    }
    //组织SOAP协议数据
    var soapXML = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ws='http://ws.cms.ivms6.hikvision.com'>"
    +"<soapenv:Header/>"
    +"<soapenv:Body>"   
    +"<ws:getAllResourceDetailByOrg>"      
    +"  <!--Optional:-->"       
    +"    <ws:token>" + tgc + "</ws:token>"         
    +"    <!--Optional:-->"        
    +"    <ws:orgCode>" + nodes.c_index_code + "</ws:orgCode>"        
    +"    <!--Optional:-->      "       
    +"    <!--Optional:-->"        
    +"    <ws:resType>10000</ws:resType><ws:operCode>10001</ws:operCode>"        
    +"</ws:getAllResourceDetailByOrg>"      
    +"</soapenv:Body>"   
    +"</soapenv:Envelope>";
    //alert(soapXML);
    //发送数据
    xhr.send(soapXML);
    
    
  }
    
    
    
  
  
  function queryTGC(){
    //创建XMLHttpRequest对象
    var xhr = new XMLHttpRequest();
    //打开连接
    xhr.open("post","http://10.1.1.4:9980/cms/services/IAuthService?wsdl",true);
    //设置数据类型
    xhr.setRequestHeader("content-type","text/xml;charset=utf-8");
    //设置回调函数
    xhr.onreadystatechange=function(){
      
      //判断是否发送成功和判断服务端是否响应成功
      if(4 == xhr.readyState && 200 == xhr.status){
        var response = xhr.responseXML.documentElement;
       // console.log(response);
        
        var node_ = response.getElementsByTagName('ns:return'); //example 
      //  console.log(node_);
        
        var node = node_[0]; //example 
     //   console.log(node);
        
      
        var va = node.textContent;
      //  console.log(va);
        
        var parser=new DOMParser();
        xmlDoc=parser.parseFromString(va,"text/xml");
      //  console.log(xmlDoc);
        
        
        //var response1 = xhr.responseXML.documentElement;
        //console.log(response1);
        
        var node_1 = xmlDoc.getElementsByTagName('row'); //example 
     //   console.log(node_1);
        
        var node1 = node_1[0]; //example 
     //   console.log(node1);
        
        var attr=node1.getAttribute("tgc"); 
    //    console.log(attr);
        
        queryMobile(attr);
        
        
      }
    }
    //组织SOAP协议数据
    var soapXML = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ws='http://ws.cms.ivms6.hikvision.com'>"
     +"<soapenv:Header/>"
    +"<soapenv:Body>"   
    +"<ws:login>"   
    +"<!--Optional:-->"      
    +" <ws:loginAccount>hbhdty</ws:loginAccount>"     
    +" <!--Optional:-->"     
    +" <ws:password>961ef2fee74bb54df8325590460a43be1451cadb5eb936d5ededc052a32764e7</ws:password>"     
    +" <!--Optional:-->"     
    +"<ws:serviceIp>10.1.1.4</ws:serviceIp>"      
    +"  <!--Optional:-->"    
    +"<ws:clientIp xsi:nil='true' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>"      
      +" <!--Optional:-->"        
      +"<ws:clientMac xsi:nil='true' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>"  
        +"</ws:login>" 
        +"</soapenv:Body>"
        +"</soapenv:Envelope>";
    //alert(soapXML);
    //发送数据
    xhr.send(soapXML);
    
    
  }
  
  queryTGC();
    
    
    function queryMobile(tgc){
    //创建XMLHttpRequest对象
    var xhr = new XMLHttpRequest();
    //打开连接
    xhr.open("post","http://10.1.1.4:9980/cms/services/ICuService?wsdl",true);
    //设置数据类型
    xhr.setRequestHeader("content-type","text/xml;charset=utf-8");
    //设置回调函数
    xhr.onreadystatechange=function(){
      
      //判断是否发送成功和判断服务端是否响应成功
      if(4 == xhr.readyState && 200 == xhr.status){
        var response = xhr.responseXML.documentElement;
   //     console.log(response);
        
        var node_ = response.getElementsByTagName('ns:return'); //example 
   //     console.log(node_);
        
        var node = node_[0]; //example 
    //    console.log(node);
        
      
        var va = node.textContent;
    //    console.log(va);
        
        var parser=new DOMParser();
        xmlDoc=parser.parseFromString(va,"text/xml");
   //     console.log(xmlDoc);
        
        
        //var response1 = xhr.responseXML.documentElement;
        //console.log(response1);
        
        var node_1 = xmlDoc.getElementsByTagName('row'); //example 
 //       console.log(node_1);
        
        var node1 = node_1[0]; //example 
  //      console.log(node1);
        
        
        var attr=node1.getAttribute("data"); 
   //     console.log(attr);
        
        
        
        attr = attr.replace(/c_org_name/g, 'text');
        
        var json = JSON.parse(attr); 
        
        for(var i = 0; i < json.length; i++){
     //     console.log(json[i]);
        }
        
        for(var i = 0; i < json.length; i++){
          json[i]['text']= json[i]['text'] + "(" + json[i]['all_count'] + ")"+ "(" + json[i]['online_count'] + ")";
        }
        
        function arrayToJson(treeArray){
            var r = [];
            var tmpMap ={};
           
            for (var i=0, l=treeArray.length; i<l; i++) {
             // 以每条数据的id作为obj的key值，数据作为value值存入到一个临时对象里面
             tmpMap[treeArray[i]["i_id"]]= treeArray[i]; 
            } 
           
            for (i=0, l=treeArray.length; i<l; i++) {
              
              if(treeArray[i]["i_parent_id"] == null)
                treeArray[i]["i_parent_id"] = 0;
              
             var key=tmpMap[treeArray[i]["i_parent_id"]];
              
             //循环每一条数据的pid，假如这个临时对象有这个key值，就代表这个key对应的数据有children，需要Push进去
             if (key) {
              if (!key["nodes"]){
                key["nodes"] = [];
                key["nodes"].push(treeArray[i]);
              }else{
               key["nodes"].push(treeArray[i]);
              }    
             } else {
              //如果没有这个Key值，那就代表没有父级,直接放在最外层
              r.push(treeArray[i]);
             }
            }
            return r
       }

        
        var jsonToArray=function (nodes) {
           var r=[];
           if (Array.isArray(nodes)) {
            for (var i=0, l=nodes.length; i<l; i++) {
             r.push(nodes[i]);
             if (Array.isArray(nodes[i]["nodes"])&&nodes[i]["nodes"].length>0)
              //将children递归的push到最外层的数组r里面
              r = r.concat(jsonToArray(nodes[i]["nodes"]));
               delete nodes[i]["nodes"];
            }
           } 
           return r;
          }

        function deepCopy(obj){
            var object;
            if(Object.prototype.toString.call(obj)=="[object Array]"){  
             object=[];
             for(var i=0;i<obj.length;i++){
              object.push(deepCopy(obj[i]))
             }  
             return object
            }
           
            if(Object.prototype.toString.call(obj)=="[object Object]"){  
             object={};
             for(var p in obj){
              object[p]=obj[p]
             }  
             return object
            }
           }

    
      //  str1 = str1.replace(/c_org_name/g, 'text');

        
 //   console.log(json);
     
      var sj = deepCopy(json);
     
    var result=arrayToJson(sj);

  //  console.log("result");
        
   // console.log(result);
        
  
     $('#tree').treeview({
          color: "#428bca",
        
          data: result,
          onNodeSelected: function(event, node) {        
            
         //   alert(node.c_device_ip);
            if(node.c_device_ip != null){
            	alert(node.c_index_code);
             // LoginPlat();
               StartPreview(node.c_index_code)
        //    alert(node.c_device_index_code);
            }
            
                queryOrg(node, tgc);
                                
           },
           onNodeUnselected: function (event, node) {
                
           }
     });
 
       
       
        //$('#tree').treeview({data: result});
        
        
        //LoginPlat();
          //StartPreview();
      }
      
      

    }
    //组织SOAP协议数据
    var soapXML = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ws='http://ws.cms.ivms6.hikvision.com'>"
         +"<soapenv:Header/>"
         +"<soapenv:Body>"
         +"<ws:getCameraStatusWithJson>"
         +"  <!--Optional:-->"
         +"  <ws:token>" + tgc + "</ws:token>"
         +"  <!--Optional:-->"
         +"  <ws:operCode>10051</ws:operCode>"
         +"  <!--Zero or more repetitions:-->" 
         +"  <ws:attrNames xsi:nil='true' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/><ws:attrNames/><ws:attrNames>all_count</ws:attrNames><ws:attrNames>c_index_code</ws:attrNames><ws:attrNames>i_parent_id</ws:attrNames><ws:attrNames>i_id</ws:attrNames><ws:attrNames>online_count</ws:attrNames>"
         +"</ws:getCameraStatusWithJson>"
         +"</soapenv:Body>"
         +"</soapenv:Envelope>"; 
         
         
         
 /*   var soapXML = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ws='http://ws.cms.ivms6.hikvision.com'>"
         +"<soapenv:Header/>"
         +"<soapenv:Body>"
         +"<ws:getAllResourceDetailWithJson>"
         +"<!--Optional:-->"   
         +"<ws:token>TGT-1092-gRpbpofRibD2wuPZ03JLSyq2Lg2gqrQ15ZZ7rOfSIatDr3x6hB-cas</ws:token>"   
         +"<!--Optional:-->"   
         +""   
         +" <!--Optional:-->"  
         +"  <ws:resType>1000</ws:resType><ws:operCode>10001</ws:operCode>" 
         +"</ws:getAllResourceDetailWithJson>"
         +"</soapenv:Body>"
         +"</soapenv:Envelope>";
          */
         
    //alert(soapXML);
    //发送数据
    xhr.send(soapXML);
  } 
    
    


    
    </SCRIPT>

<SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
    LoginPlat();
    preview.SetMainToolBarShow("true");
      //StartPreview();
</SCRIPT>

  

<script src="../../assets/plugins/bootstrap-treeview/js/bootstrap-treeview.js" type="text/javascript"></script>


</body>
</html>